package com.example.demo.service.Impl;

import com.example.demo.config.BaseUserInfo;
import com.example.demo.config.LoginHandlerInterceptor;
import com.example.demo.mapper.EnchantMapper;
import com.example.demo.pojo.Enchanter;
import com.example.demo.pojo.Lifebook;
import com.example.demo.pojo.LogTest;
import com.example.demo.pojo.UserInfoEnu;
import com.example.demo.service.EnchantService;
import com.example.demo.utils.AliOSSUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

@Service

public class EnchantServiceImpl implements EnchantService {
    @Autowired
    private EnchantMapper enchantMapper;
    @Autowired
    private LoginHandlerInterceptor loginHandlerInterceptor;
    //勾魂计划
    @Override
    public PageInfo queryEnchant(Integer page, Integer limit, String name) {
        PageHelper.startPage(page,limit);
        List<Lifebook> list = enchantMapper.queryEnchant(name);
        PageInfo<Lifebook> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
    //勾魂人数总数搜索
    @Override
    public int queryEnchants() {
        return enchantMapper.queryEnchants();
    }

    //勾魂完成
    @Override
    public void setEnchant(Lifebook lifebook) {
        //勾魂使者id为1代表特殊值
        LogTest logTest = loginHandlerInterceptor.UserTokenLog();
        lifebook.setReaperid(logTest.getId());
        enchantMapper.setEnchant(lifebook.getId(),lifebook.getSet(),lifebook.getReaperid());
    }


    //勾魂添加
    @Override
    public void addEnchanter(String upload, String name, Integer gender, String description, Integer status) {
        String uuid = UUID.randomUUID().toString().replace("-", "");
        LocalDateTime createTime  = LocalDateTime.now();
        Integer role = 2;
        enchantMapper.addEnchanter(name,uuid,gender,upload,description,createTime,role,status);
    }
    //勾魂使者列表
    @Override
    public PageInfo queryEnchanter(Integer page,Integer limit,String name) {
        PageHelper.startPage(page,limit);
        List<Enchanter> list = enchantMapper.queryEnchanter(name);
        PageInfo<Enchanter> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void updateEnchanter(Enchanter enchanter) {
        System.out.println(enchanter);
        enchantMapper.updateEnchanter(enchanter);

    }

    @Override
    public void deleteEnchanter(String  uuid) {
        enchantMapper.deleteEnchanter(uuid);
    }




}
